<?php
// +-------------------------------------------------------
// | Name： 星空框架  产品规格模型
// +-------------------------------------------------------
// | Version: V5.0
// +-------------------------------------------------------
// | Author: xkyinzhe <zhonghuaxinxing@sina.cn>
// +-------------------------------------------------------
// | Time: 2021-04-25 13：19
// +-------------------------------------------------------
declare(strict_types=1);

namespace app\common\model;

use think\model\concern\SoftDelete;

/**
 * @xk 产品规格模型
 */
class GoodsSpec extends BaseModel
{
  use SoftDelete;
  protected $name = 'goodsSpec';
  protected $pk = 'goods_spec_id';
  protected $deleteTime = 'delete_time';
  /**
   * @xk 写入前操作
   *
   * @method onBeforeWrite
   * @param  [type]                  $data                     [description]
   * @return [type]                                            [description]
   * @Author xkyinzhe                <zhonghuaxinxing@sina.cn>
   * @Time   2021-04-22T17:31:28+080
   */
  public static function onBeforeWrite($data)
  {
      unset($data['act']);
      unset($data['controllers']);
      unset($data['actions']);
      if (!$data->create_time) {
          $data->update_time = $data->create_time = date('Y-m-d H:i:s');
      }
      $data->update_time = date('Y-m-d H:i:s'); // 操作时间 实际发布时间
      if($data->order_id <= 0){
        $data->order_id = self::max('order_id')+1;
      }
  }
  /**
   * @xk 删除前操作
   *
   * @method onBeforeDelete
   * @param  [type]                  $data                     [description]
   * @return [type]                                            [description]
   * @Author xkyinzhe                <zhonghuaxinxing@sina.cn>
   * @Time   2021-04-22T17:31:48+080
   */
  public static function onBeforeDelete($data)
  {
      // 删除前：获取的删除前数据，还没删除
  }
  /**
   * @xk 模型一对多关联
   *
   * @method getSpecValue
   * @return [type]                  [description]
   * @Author xkyinzhe                <zhonghuaxinxing@sina.cn>
   * @Time   2021-04-26T09:42:06+080
   */
  public function getSpecValue(){
    return $this->hasMany('goodsSpecValue', 'goods_spec_id', 'goods_spec_id');
  }
}
